package org.dream.domain;

// Generated 2009-9-13 14:47:42 by Hibernate Tools 3.2.4.GA
import java.util.List;

import org.dream.persistence.PersistenceService;
import org.dream.persistence.PersistenceServiceImpl;

public class Stock implements java.io.Serializable, Comparable<Stock> {

	private String id;

	private String code;
	private String name;
	private String myflag;
	private String stime;// 上市时间
	private String etime;// 最后交易日
	private String bkmc;
	private List<Daydeal> daydeals;
	private static PersistenceService persistenceService = new PersistenceServiceImpl();

	public void setBkmc(String bkmc) {
		this.bkmc = bkmc;
	}

	public String getBkmc() {
		return bkmc;
	}

	public String getStime() {
		return stime;
	}

	public void setStime(String stime) {
		this.stime = stime;
	}

	public String getEtime() {
		return etime;
	}

	public void setEtime(String etime) {
		this.etime = etime;
	}

	public Stock() {
	}

	public Stock(String id) {
		this.id = id;
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMyflag() {
		return myflag;
	}

	public void setMyflag(String myflag) {
		this.myflag = myflag;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int compareTo(Stock o) {
		
		return o.getJlScore().compareTo(this.getJlScore());
	}

	public Integer getJlScore() {
		// return new HLYService().countJlScore(this.daydeals);
		return 0;
	}

	public List<Daydeal> getDaydeals() {
		return daydeals;
	}

	/**
	 * 激活领域对象
	 */
	public static synchronized  Stock activationDomain(String code) {
		
		Stock stock = persistenceService.getStockByCode(code);
		stock.daydeals = persistenceService.findDayDealsByCode(code);
		return stock;
	}

	/**
	 * 激活领域对象
	 */
	public void activationDomain() {
		this.daydeals = persistenceService.findDayDealsByCode(code);
	}

	/**
	 * 得到最近 累计涨幅
	 */
	public double getLJMaxZhangfu(int startDayNum, int day) {
		double maxZhangFu = 0.0;
		double zhangFu = 0.0;
		for (int i = startDayNum; i > startDayNum - 5; i--) {
			if (i < 0) {
				break;
			}
			zhangFu += daydeals.get(i).getRiseWidth();
			if (zhangFu - maxZhangFu > 0) {
				maxZhangFu = zhangFu;
			}
		}
		return maxZhangFu;
	}

}
